package appEngineSample.appsample.managedbeans;

import java.util.ArrayList;
import java.util.List;

import javax.faces.application.FacesMessage;
import javax.faces.bean.ApplicationScoped;
import javax.faces.bean.ManagedBean;
import javax.faces.context.FacesContext;

import appEngineSample.appsample.SampleEntities;
import appEngineSample.appsample.dao.ClienteJpaDAO;
import appEngineSample.appsample.models.Cliente;
import appEngineSample.appsample.models.Dependente;

import com.google.appengine.api.datastore.Query;

/**
 * @author Anderson Bernardo
 * @since 25/07/2013
 */
@ManagedBean(name = "clienteMB")
@ApplicationScoped
public class ClienteBean {

	private Cliente cliente = new Cliente();
	private List<Cliente> clientes = new ArrayList<Cliente>();
	private List<Dependente> dependentes = new ArrayList<Dependente>();
	private Dependente depen = new Dependente();
	
	private ClienteJpaDAO clienteDAO = new ClienteJpaDAO();

	public String cadastrarCliente(String teste) {
		System.out.println("Testando JSF 2 e App Engine..." + teste);
		clienteDAO.insert(cliente);
		return "index.xhtml";
	}

	public void cadastrarDependente() {
		dependentes.add(depen);
		depen = new Dependente();
	}

	public List<Cliente> buscaClientes() {
		return clienteDAO.listarClientes();
	}

	public Dependente getDepen() {
		return depen;
	}

	public void setDepen(Dependente depen) {
		this.depen = depen;
	}

	public Cliente getCliente() {
		return cliente;
	}

	public void setCliente(Cliente cliente) {
		this.cliente = cliente;
	}

	public List<Cliente> getClientes() {
		return clientes;
	}

	public void setClientes(List<Cliente> clientes) {
		this.clientes = clientes;
	}

	public List<Dependente> getDependentes() {
		return dependentes;
	}

	public void setDependentes(List<Dependente> dependentes) {
		this.dependentes = dependentes;
	}

}
